﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Demo3
{
    /// <summary>
    /// 随机生成50个同学的成绩
    /// 1.求平均分
    /// 2.输出排名前10位的成绩
    /// 3.输出成绩合格的成绩
    /// </summary>
    class Program
    {
        static void Main(string[] args)
        {
            double[] grades = new double[50];
            // 总分
            var sum = 0d;
            // 平均分
            var avg = 0d;
            var rnd = new Random();
            for (int i = 0; i < grades.Length; i++)
            {
                grades[i] =100* rnd.NextDouble();
                if (grades[i] > 100)
                    grades[i] = 100;

                // 求总分
                sum += grades[i];
            }
            avg = sum / grades.Length;

            for (int i = 0; i < grades.Length; i++)
                Console.WriteLine($"第{i + 1}个同学的成绩是{grades[i]:0.0}");
            Console.WriteLine("倒序排序");
            // 数组中排序的工具
            Array.Sort(grades); 
            // 把数组元素倒置的工具
            Array.Reverse(grades);
            for (int i = 0; i < 10; i++)
                Console.WriteLine($"第{i + 1}个同学的成绩是{grades[i]:0.0}");
            Console.WriteLine($"总分为{sum:0.0}，平均分是{avg:0.0}");
            Console.ReadKey();
        }
    }
}
